const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const News = sequelize.define('News', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  title: {
    type: DataTypes.STRING(200),
    allowNull: false,
    comment: '新闻标题'
  },
  summary: {
    type: DataTypes.TEXT,
    allowNull: false,
    comment: '新闻摘要'
  },
  content: {
    type: DataTypes.TEXT('long'),
    allowNull: false,
    comment: '新闻内容'
  },
  category: {
    type: DataTypes.ENUM('tech', 'finance', 'sports', 'entertainment'),
    allowNull: false,
    comment: '新闻分类'
  },
  image: {
    type: DataTypes.STRING(500),
    allowNull: false,
    comment: '新闻图片URL'
  },
  views: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '阅读量'
  },
  author: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '作者'
  },
  status: {
    type: DataTypes.ENUM('draft', 'published', 'archived'),
    defaultValue: 'published',
    comment: '状态：草稿、已发布、已归档'
  }
}, {
  tableName: 'news',
  comment: '新闻信息表',
  indexes: [
    {
      name: 'idx_category',
      fields: ['category']
    },
    {
      name: 'idx_status',
      fields: ['status']
    },
    {
      name: 'idx_title',
      fields: ['title']
    }
  ]
});

module.exports = News; 